//
//  KDLibraryLocationWindowController.m
//  Source List
//
//  Created by Keith Duncan on 15/05/2008.
//  Copyright 2008 Disney Store. All rights reserved.
//

#import "KDLibraryWindowController.h"

@implementation KDLibraryWindowController

@synthesize expectedLocation;

- (id)initWithNibName:(NSString *)name bundle:(NSBundle *)bundle {
	return [super initWithWindowNibName:name owner:self];
}

- (void)dealloc {
	[expectedLocation release];
	
	[super dealloc];
}

- (IBAction)browse:(id)sender {
	NSOpenPanel *open = [[NSOpenPanel openPanel] retain];
	
	[open setCanChooseDirectories:NO];
	[open setCanCreateDirectories:NO];
	[open setAllowsMultipleSelection:NO];
	
	if ([open runModalForDirectory:[expectedLocation stringByDeletingLastPathComponent] file:nil types:[NSArray arrayWithObject:@"xml"]] == NSOKButton) {
		[libraryPathField setStringValue:[open filename]];
		[NSApp stopModal];
	}
	
	[open release];
}

- (NSString *)requestLibraryLocation {
	[self showWindow:nil];
	[[self window] center];
	
	[NSApp runModalForWindow:[self window]];
	
	[NSApp endSheet:[self window]];
	[self close];
	
	return [[[libraryPathField stringValue] copy] autorelease];
}

- (IBAction)endRequest:(id)sender {
	[NSApp stopModal];
}

@end
